package com.example.sql_2_code_demo.service.impl;

import com.example.sql_2_code_demo.entity.OrderItemDetail;
import com.example.sql_2_code_demo.dao.OrderItemDetailDao;
import com.example.sql_2_code_demo.service.OrderItemDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单商品属性表(OrderItemDetail)表服务实现类
 *
 * @author makejava
 * @since 2022-10-09 10:01:37
 */
@Service("orderItemDetailService")
public class OrderItemDetailServiceImpl implements OrderItemDetailService {
    @Resource
    private OrderItemDetailDao orderItemDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public OrderItemDetail queryById(Long id) {
        return this.orderItemDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param orderItemDetail 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderItemDetail> queryByPage(OrderItemDetail orderItemDetail, PageRequest pageRequest) {
        long total = this.orderItemDetailDao.count(orderItemDetail);
        return new PageImpl<>(this.orderItemDetailDao.queryAllByLimit(orderItemDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderItemDetail 实例对象
     * @return 实例对象
     */
    @Override
    public OrderItemDetail insert(OrderItemDetail orderItemDetail) {
        this.orderItemDetailDao.insert(orderItemDetail);
        return orderItemDetail;
    }

    /**
     * 修改数据
     *
     * @param orderItemDetail 实例对象
     * @return 实例对象
     */
    @Override
    public OrderItemDetail update(OrderItemDetail orderItemDetail) {
        this.orderItemDetailDao.update(orderItemDetail);
        return this.queryById(orderItemDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.orderItemDetailDao.deleteById(id) > 0;
    }
}
